package com.wisezone.demo0216;

import javax.imageio.IIOException;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;

public class TestURL {
    public static void main(String[] args) {
        try
        {
//            URL url=new URL("https://www.tupianzj.com/");
//            URL fileUrl=new URL(url,"meinv/20211102/234986.html?uu=aa");
//            System.out.println(fileUrl.getQuery());
            URL url=new URL("https://img.lianzhixiu.com/uploads/allimg/202111/9999/10879b98e1.jpg");
            InputStream is= url.openStream();
//            System.out.println(is);
            File file=new File("out/a01.jpg");
            FileOutputStream fileOutputStream =new FileOutputStream(file);

            int length=0;
            byte[] bytes=new byte[1024];
            while((length=is.read(bytes))!=-1){
                fileOutputStream.write(bytes,0,length);
            }
            fileOutputStream.flush();

        }catch (MalformedURLException e){
            e.printStackTrace();
        }catch (IOException e){
            e.printStackTrace();
        }

    }
}
